package com.shangxian.giveithome.result;


import com.shangxian.giveithome.code.Code;
import com.shangxian.giveithome.code.CommonCode;
import lombok.Data;

@Data
public class Result<T> {

    private boolean status;

    /**
     * 错误码
     */
    private Integer code;

    /**
     * 提示信息
     */
    private String message;


    /**
     * 返回内容
     */
    private T data;

    public Result() {
    }

    public Result(Code code, T date) {
        this.status = code.success();
        this.code = code.code();
        this.message = code.message();
        this.data = date;
    }

    public Result(Code code) {
        this.status = code.success();
        this.code = code.code();
        this.message = code.message();
        this.data = null;
    }

    public static Result<Object> success() {
        return new Result<>(CommonCode.SUCCESS);
    }

    public static Result<Object> success(Code code) {
        return new Result<>(code);
    }

    public static Result<Object> success(Object date) {
        return new Result<>(CommonCode.SUCCESS, date);
    }

    public static Result<Object> success(Code code, Object date) {
        return new Result<>(code, date);
    }

    public static Result<Object> update_success() {
        return new Result<>(CommonCode.UPDATE_SUCCESS);
    }

    public static Result<Object> update_success(Object date) {
        return new Result<>(CommonCode.UPDATE_SUCCESS, date);
    }


    public static Result<Object> update_success(Code code, Object date) {
        return new Result<>(code, date);
    }

    public static Result<Object> delete_success() {
        return new Result<>(CommonCode.DELETE_SUCCESS);
    }

    public static Result<Object> error(Code code) {
        return new Result<>(code);
    }

    public static Result<Object> error(Code code, Object date) {
        return new Result<>(code, date);
    }
}
